/**
 *  Copyright (c)  2010  Angel Ortiz.
 *  Permission is granted to copy, distribute and/or modify this document
 *  under the terms of the GNU Free Documentation License, Version 1.3
 *  or any later version published by the Free Software Foundation;
 *  with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
 *  A copy of the license is included in the section entitled "GNU
 *  Free Documentation License". 
 */

package view;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;

import javax.swing.JPanel;

import data.Images;
import data.OverviewData;

/**
 * @author Angel Ortiz
 * @date 03/19/2010
 * 
 */
public abstract class OverviewImgTextLayer extends JPanel {

	protected OverviewData data;
	protected Images images;
	private int height, width, xCoordinate, yCoordinate;
	private static final long serialVersionUID = -4564717424258205114L;

	public abstract String getTitle();

	public abstract String[] getColumns();

	public abstract String[][] getData();

	public abstract String[] getRow(int index);

	public abstract int getHeight();

	public abstract int getWidth();

	public abstract int getXCoordinate();

	public abstract int getYCoordinate();

	public abstract int getNumberOfRows();

	public OverviewImgTextLayer(OverviewData data, Images images) {
		this.data = data;
		this.images = images;
		this.setFocusable(false);
		this.setOpaque(false);

		this.setLocation(0, 0);
		height = 600;
		width = 1024;
		xCoordinate = 0;
		yCoordinate = 0;

		this.setSize(width, height);
		this.setLocation(xCoordinate, yCoordinate);

	}

	/**
	 * painting table algorithm for statistical overviews
	 */
	public void paint(Graphics g) {
		String title = this.getTitle();
		String[] columns = this.getColumns();
		int h = this.getHeight();
		int w = this.getWidth();
		int x = this.getXCoordinate();
		int y = this.getYCoordinate();
		this.setSize(w, h);
		this.setLocation(x, y);

		Font titleFont = new Font("Arial", Font.BOLD, 20);
		Font columnNamesFont = new Font("Arial", Font.BOLD, 16);
		Font dataFont = new Font("Arial", Font.BOLD, 12);

		g.setColor(Color.green);
		g.setFont(titleFont);
		int TitleLength = title.getBytes().length;
		g.drawString(title, (512 - (27 * (TitleLength / 5))), 37);

		g.setFont(columnNamesFont);

		for (int i = 0; i < 10; i++) {
			int length = columns[i].getBytes().length;
			g.drawString(columns[i], ((x + 36) - (7 * (length / 2))), 95);
			x = x + 100;

		}

		y = 40;

		g.setFont(dataFont);
		for (int i = 0; i < 9; i++) {
			x = this.getXCoordinate();
			String[] row = this.getRow(i);
			if (row != null) {
				for (int j = 0; j < 10; j++) {
					g.drawString(row[j], x + 11, y + 100);
					x = x + 100;
				}
				y = y + 50;
			} else
				break;
		}
		
		int[] cursor = this.data.getCursorPosition();
		g.drawRect(cursor[0] * 100, 125 + cursor[1] * 50, 94, 20);
		g.drawRect(cursor[0] * 100 + 1, 125 + cursor[1] * 50 + 1, 92, 18);
		
		if(this.data.needsArrowDown())
			g.drawImage(images.getImage("arrow_down"), 471, 574, this);
		if(this.data.needsArrowUp())
			g.drawImage(images.getImage("arrow_up"), 516, 569, this);
	}
}
